package cn.richard.demo.ruleengine.config;

import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.api.RulesEngineParameters;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeansConfig {
	
	@Bean
	public RulesEngine getRulesEngine() {
		RulesEngineParameters parameters = new RulesEngineParameters()
				.skipOnFirstAppliedRule(true)
        		//.priorityThreshold(10)
        		//.skipOnFirstFailedRule(true)
        		//.skipOnFirstNonTriggeredRule(true)
				;
		
		DefaultRulesEngine rulesEngine = new DefaultRulesEngine(parameters);
		
		rulesEngine.registerRuleListener(new MyRuleListener());
		
		rulesEngine.registerRulesEngineListener(new MyRulesEngineListener());
		
		return rulesEngine;
	}
}
